package ru.common.util;

import java.util.concurrent.*;

/**
 * @author: ATroshanin
 * Date: 01.06.2010
 * Time: 12:52:24
 */
public class ThreadPoolManager {

    private static ThreadPoolManager instance = new ThreadPoolManager();

    private ThreadPoolExecutor messagingServersPacketsExecutor;
    private ThreadPoolExecutor battleServersPacketsExecutor;
    private ScheduledExecutorService scheduledExecutor;

    private ThreadPoolManager() {
        scheduledExecutor = Executors.newScheduledThreadPool(2);
        messagingServersPacketsExecutor = new ThreadPoolExecutor(2, 4, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
        battleServersPacketsExecutor = new ThreadPoolExecutor(2, 4, 100, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
    }

    public static ThreadPoolManager getInstance() {
        return instance;
    }

    public void executeMessageServersPacket(Runnable task) {
        messagingServersPacketsExecutor.execute(task);
    }

    public void executeBattleServersPacket(Runnable task) {
        battleServersPacketsExecutor.execute(task);
    }

    public void scheduleTask(Runnable task, long delay) {
        scheduledExecutor.schedule(task, delay, TimeUnit.MILLISECONDS);
    }
}
